package com.night.icm.controller.business;

import com.night.icm.common.night_enum.CompAssessProcessStatus;
import com.night.icm.model.base.comprehensive_test.ComprehensiveScoreDTO;
import com.night.icm.service.base.service.comprehensive_test.ComprehensiveScoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ComprehensiveScoreController
 * 学生管理自己的综合测评
 *
 * @author Liao ZhiYong
 * @date 2020/2/12
 */
@Api(tags = "综合测评管理")
@RestController
@RequestMapping("/api/icm-comprehensive-score")
public class ComprehensiveScoreController {


    private final ComprehensiveScoreService comprehensiveScoreService;

    @Autowired
    public ComprehensiveScoreController(ComprehensiveScoreService comprehensiveScoreService) {
        this.comprehensiveScoreService = comprehensiveScoreService;
    }

    @ApiOperation(value = "查找学生综合测评")
    @GetMapping(value = "/findAll")
    public List<ComprehensiveScoreDTO> findAll(
            @ApiParam(value = "学生id", required = true) @RequestParam(value = "studentId") String studentId,
            @ApiParam(value = "流程状态", required = true) @RequestParam(value = "compAssessProcessStatus") CompAssessProcessStatus compAssessProcessStatus
    ) {
        return this.comprehensiveScoreService.findAll(studentId, compAssessProcessStatus);
    }

    @ApiOperation(value = "模糊查询学生综合测评")
    @GetMapping(value = "")
    public List<ComprehensiveScoreDTO> search(
            @ApiParam(value = "所属学院name") @RequestParam(value = "academyName", required = false) String academyName,
            @ApiParam(value = "所属专业name") @RequestParam(value = "professionName", required = false) String professionName,
            @ApiParam(value = "所属班级name") @RequestParam(value = "className", required = false) String className,
            @ApiParam(value = "所属班级id") @RequestParam(value = "classId", required = false) String classId,
            @ApiParam(value = "学生姓名") @RequestParam(value = "studentName", required = false) String studentName,
            @ApiParam(value = "学生id") @RequestParam(value = "studentId", required = false) String studentId,
            @ApiParam(value = "所属年度") @RequestParam(value = "year", required = false) String year,
            @ApiParam(value = "流程状态") @RequestParam(value = "compAssessProcessStatus", required = false) CompAssessProcessStatus compAssessProcessStatus,
            @ApiParam(value = "学生code") @RequestParam(value = "studentCode", required = false) String studentCode
    ){
        return this.comprehensiveScoreService.search(academyName, professionName, className, studentName, year, compAssessProcessStatus, classId, studentId, studentCode);
    }

    @ApiOperation(value = "新建年度综合测评")
    @PostMapping(value = "")
    public ComprehensiveScoreDTO create(@ApiParam(value = "综合测评信息", required = true) @RequestBody @Validated ComprehensiveScoreDTO comprehensiveScoreDTO) {
        return this.comprehensiveScoreService.create(comprehensiveScoreDTO);
    }

    @ApiOperation(value = "提交综合测评数据")
    @PutMapping(value = "/{id}")
    public ComprehensiveScoreDTO compelete(
            @ApiParam(value = "综合测评id", required = true) @PathVariable(name = "id") String id,
            @ApiParam(value = "综合测评信息", required = true) @RequestBody @Validated ComprehensiveScoreDTO comprehensiveScoreDTO
    ) {
        // 保存更新的综合测评数据和文件
        return this.comprehensiveScoreService.complete(id, comprehensiveScoreDTO);
    }

    @ApiOperation(value = "通过id查找综合测评信息")
    @GetMapping(value = "{id}")
    public ComprehensiveScoreDTO findById(@ApiParam(value = "综合测评id", required = true) @PathVariable(name = "id") String id) {
        return this.comprehensiveScoreService.findById(id);
    }
}